<?php
//error_reporting(0);

/**
 * 达人推荐管理 
 * 
 * @copyright caijian
 * @since 2012-03-21
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");



$g_cgival = array();
$g_pro = array();
$g_show = array();

function show_pro()
{
	global $g_show;
	
	$smarty = p_get_smarty ();

	if ($g_show['error']) {
		$smarty->assign ( array('g_show'=>$g_show) );
		$smarty->display ( "admin_error.html" );
	} else {
		$smarty->assign ( $g_show );
		$smarty->display ( "foodv2/user/user_daren.html" );
	}
}


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;

	
	cgi::get($g_cgival["s_nickname"], "s_nickname", "");
	$g_cgival["s_nickname"] = string::un_script_code($g_cgival["s_nickname"]);
	$g_cgival["s_nickname"] = string::un_html($g_cgival["s_nickname"]);

	cgi::get($g_cgival["s_status"], "s_status", 0);

	// 分页
	cgi::get($g_cgival["p"], "p", 1);
	cgi::get($g_cgival["pcount"], "pcount", 20);

	$g_cgival["p"] = intval($g_cgival["p"]);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
	if (! $g_cgival['pcount'] ) $g_cgival['pcount'] = 20;
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	global $config;

	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	$admin_id = admin::admin_get_login_uid();
	$admin_name = admin::admin_get_login_user_name();

	$db_daren = new db_food_user_daren();

	if ($site_id == 900 ) {
		$where = "1";
	} else {
		$where = "site_id='{$site_id}'";
	}

	if ($g_cgival['s_status'] == 1) {
		$where .= " and status=1";
	} else if ($g_cgival['s_status'] == -1) {
		$where .= " and status=0";
	}

	if ($g_cgival['s_nickname']) {
		$where .= " and nickname like '%{$g_cgival['s_nickname']}%'";
	}

	$data = $db_daren->admin_get_food_user_daren_list($where,$g_cgival["p"],$g_cgival['pcount']);

	$fuser = new mod_food_user();

	foreach ($data['result'] as $row) {
		$userinfo = $fuser->get_user_info($row['uid']);

		$row['icon'] = $userinfo['weibo_user_info']['profile_image_url'];
		$row['all_love_count'] = $userinfo['food_user_info']['all_love_count'];
		$row['album_count'] = $userinfo['food_user_info']['album_count'];
		$g_show['data'][] = $row;

	}

	$g_show['s_nickname'] = $g_cgival['s_nickname'];
	$g_show['s_status'] = $g_cgival['s_status'];

//print_r($g_show);exit;

/*
		if ($i++ >=6) {
			$db_daren->admin_update_food_user_daren_status($row['uid'], $site_id, 0, 1, $admin_id, $admin_name);
		}
	
	
	// Pager 
	$max_page = page_bar::get_page_max($g_show["count"], $g_cgival['pcount'], $g_cgival["p"]);
	
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar2($page_bar_style);

*/
}

try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/main_nav.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


